package com.zzc.zzcapi.service.impl.inner;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzc.keleapiCommon.model.dto.InterfaceInfoDTO;
import com.zzc.keleapiCommon.service.InnerInterfaceInfoService;
import com.zzc.zzcapi.common.ErrorCode;
import com.zzc.zzcapi.exception.BusinessException;
import com.zzc.zzcapi.model.entity.InterfaceInfo;
import com.zzc.zzcapi.service.InterfaceInfoService;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

@DubboService
public class InnerInterfaceInfoServiceImpl implements InnerInterfaceInfoService {
    @Resource
    InterfaceInfoService interfaceInfoService;
    @Override
    public InterfaceInfoDTO getInterfaceInfoDTO(String url, String method) {
        QueryWrapper<InterfaceInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("url", url).eq("method", method).eq("status", 1);
        InterfaceInfo interfaceInfo = interfaceInfoService.getOne(queryWrapper);
        if(interfaceInfo == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR);
        }
        InterfaceInfoDTO infoDTO = new InterfaceInfoDTO();
        BeanUtil.copyProperties(interfaceInfo, infoDTO);
        return infoDTO;
    }
}
